
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/28/2013 17:13:56
-- Generated from EDMX file: ORM\DB.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Inscriptionem];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_MemberRoleMember]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MemberRoles] DROP CONSTRAINT [FK_MemberRoleMember];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleMemberRole]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MemberRoles] DROP CONSTRAINT [FK_RoleMemberRole];
GO
IF OBJECT_ID(N'[dbo].[FK_MemberMemberSettings]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Members] DROP CONSTRAINT [FK_MemberMemberSettings];
GO
IF OBJECT_ID(N'[dbo].[FK_LanguageSection]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Sections] DROP CONSTRAINT [FK_LanguageSection];
GO
IF OBJECT_ID(N'[dbo].[FK_SectionPage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Pages] DROP CONSTRAINT [FK_SectionPage];
GO
IF OBJECT_ID(N'[dbo].[FK_SectionCategory]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Categories] DROP CONSTRAINT [FK_SectionCategory];
GO
IF OBJECT_ID(N'[dbo].[FK_PostComment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Comments] DROP CONSTRAINT [FK_PostComment];
GO
IF OBJECT_ID(N'[dbo].[FK_PageComment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Comments] DROP CONSTRAINT [FK_PageComment];
GO
IF OBJECT_ID(N'[dbo].[FK_MemberPage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Pages] DROP CONSTRAINT [FK_MemberPage];
GO
IF OBJECT_ID(N'[dbo].[FK_MemberComment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Comments] DROP CONSTRAINT [FK_MemberComment];
GO
IF OBJECT_ID(N'[dbo].[FK_MemberPost]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Posts] DROP CONSTRAINT [FK_MemberPost];
GO
IF OBJECT_ID(N'[dbo].[FK_PagePageTags]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PageTags] DROP CONSTRAINT [FK_PagePageTags];
GO
IF OBJECT_ID(N'[dbo].[FK_PageTagsTag]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PageTags] DROP CONSTRAINT [FK_PageTagsTag];
GO
IF OBJECT_ID(N'[dbo].[FK_PostPostTags]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostTags] DROP CONSTRAINT [FK_PostPostTags];
GO
IF OBJECT_ID(N'[dbo].[FK_TagPostTags]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostTags] DROP CONSTRAINT [FK_TagPostTags];
GO
IF OBJECT_ID(N'[dbo].[FK_PostSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Posts] DROP CONSTRAINT [FK_PostSet];
GO
IF OBJECT_ID(N'[dbo].[FK_LanguageTag]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tags] DROP CONSTRAINT [FK_LanguageTag];
GO
IF OBJECT_ID(N'[dbo].[FK_MemberMemberPasswordRemind]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MemberPasswordReminds] DROP CONSTRAINT [FK_MemberMemberPasswordRemind];
GO
IF OBJECT_ID(N'[dbo].[FK_ContactRequestMember]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContactRequests] DROP CONSTRAINT [FK_ContactRequestMember];
GO
IF OBJECT_ID(N'[dbo].[FK_PostPostCategory]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostCategories] DROP CONSTRAINT [FK_PostPostCategory];
GO
IF OBJECT_ID(N'[dbo].[FK_CategoryPostCategory]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostCategories] DROP CONSTRAINT [FK_CategoryPostCategory];
GO
IF OBJECT_ID(N'[dbo].[FK_ContactRequestContactResponse]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContactResponses] DROP CONSTRAINT [FK_ContactRequestContactResponse];
GO
IF OBJECT_ID(N'[dbo].[FK_MemberContactResponse]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContactResponses] DROP CONSTRAINT [FK_MemberContactResponse];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Members]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Members];
GO
IF OBJECT_ID(N'[dbo].[Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Roles];
GO
IF OBJECT_ID(N'[dbo].[MemberRoles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MemberRoles];
GO
IF OBJECT_ID(N'[dbo].[MemberSettings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MemberSettings];
GO
IF OBJECT_ID(N'[dbo].[Sections]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sections];
GO
IF OBJECT_ID(N'[dbo].[Languages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Languages];
GO
IF OBJECT_ID(N'[dbo].[Posts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Posts];
GO
IF OBJECT_ID(N'[dbo].[Comments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Comments];
GO
IF OBJECT_ID(N'[dbo].[Pages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Pages];
GO
IF OBJECT_ID(N'[dbo].[Tags]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tags];
GO
IF OBJECT_ID(N'[dbo].[Categories]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Categories];
GO
IF OBJECT_ID(N'[dbo].[PageTags]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PageTags];
GO
IF OBJECT_ID(N'[dbo].[PostTags]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PostTags];
GO
IF OBJECT_ID(N'[dbo].[Sets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Sets];
GO
IF OBJECT_ID(N'[dbo].[LogRequests]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LogRequests];
GO
IF OBJECT_ID(N'[dbo].[LogExceptions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LogExceptions];
GO
IF OBJECT_ID(N'[dbo].[MemberPasswordReminds]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MemberPasswordReminds];
GO
IF OBJECT_ID(N'[dbo].[ContactRequests]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ContactRequests];
GO
IF OBJECT_ID(N'[dbo].[PostCategories]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PostCategories];
GO
IF OBJECT_ID(N'[dbo].[ContactResponses]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ContactResponses];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Members'
CREATE TABLE [dbo].[Members] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [NickName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL,
    [BirthDate] datetime  NULL,
    [Mail] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [IsReadOnly] bit  NOT NULL,
    [IsRegistrationApproved] bit  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL,
    [MemberSettings_ID] int  NOT NULL
);
GO

-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL
);
GO

-- Creating table 'MemberRoles'
CREATE TABLE [dbo].[MemberRoles] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Members_ID] int  NOT NULL,
    [Role_ID] int  NOT NULL
);
GO

-- Creating table 'MemberSettings'
CREATE TABLE [dbo].[MemberSettings] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [SiteLink] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [IsMailVisible] bit  NOT NULL,
    [IsRealNameVisible] bit  NOT NULL,
    [IsBirthDateVisible] bit  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL
);
GO

-- Creating table 'Sections'
CREATE TABLE [dbo].[Sections] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [LocalizedName] nvarchar(max)  NOT NULL,
    [IsDefault] bit  NOT NULL,
    [Order] int  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL,
    [Language_ID] int  NOT NULL
);
GO

-- Creating table 'Languages'
CREATE TABLE [dbo].[Languages] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [LocalizedName] nvarchar(max)  NOT NULL,
    [IsDefault] bit  NOT NULL,
    [Order] int  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL
);
GO

-- Creating table 'Posts'
CREATE TABLE [dbo].[Posts] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [IsPublished] bit  NOT NULL,
    [IsCommentable] bit  NOT NULL,
    [IsSectionPinned] bit  NOT NULL,
    [IsCategoryPinned] bit  NOT NULL,
    [ViewCount] int  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL,
    [Member_ID] int  NOT NULL,
    [Set_ID] int  NULL
);
GO

-- Creating table 'Comments'
CREATE TABLE [dbo].[Comments] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [IsPublished] bit  NOT NULL,
    [IsDeleted] bit  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL,
    [Post_ID] int  NULL,
    [Page_ID] int  NULL,
    [Member_ID] int  NOT NULL
);
GO

-- Creating table 'Pages'
CREATE TABLE [dbo].[Pages] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [IsPublished] bit  NOT NULL,
    [IsCommentable] bit  NOT NULL,
    [IsSectionPinned] bit  NOT NULL,
    [ViewCount] int  NOT NULL,
    [Order] int  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL,
    [Section_ID] int  NOT NULL,
    [Member_ID] int  NOT NULL
);
GO

-- Creating table 'Tags'
CREATE TABLE [dbo].[Tags] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Language_ID] int  NOT NULL
);
GO

-- Creating table 'Categories'
CREATE TABLE [dbo].[Categories] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Order] int  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL,
    [Section_ID] int  NOT NULL
);
GO

-- Creating table 'PageTags'
CREATE TABLE [dbo].[PageTags] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Page_ID] int  NOT NULL,
    [Tag_ID] int  NOT NULL
);
GO

-- Creating table 'PostTags'
CREATE TABLE [dbo].[PostTags] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Post_ID] int  NOT NULL,
    [Tag_ID] int  NOT NULL
);
GO

-- Creating table 'Sets'
CREATE TABLE [dbo].[Sets] (
    [ID] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'LogRequests'
CREATE TABLE [dbo].[LogRequests] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [URL] nvarchar(max)  NOT NULL,
    [ReferrerURL] nvarchar(max)  NOT NULL,
    [UserHostAddress] nvarchar(max)  NOT NULL,
    [UserAgent] nvarchar(max)  NOT NULL,
    [CreatedDate] datetime  NOT NULL
);
GO

-- Creating table 'LogExceptions'
CREATE TABLE [dbo].[LogExceptions] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [URL] nvarchar(max)  NOT NULL,
    [Message] nvarchar(max)  NOT NULL,
    [Trace] nvarchar(max)  NOT NULL,
    [CreatedDate] datetime  NOT NULL
);
GO

-- Creating table 'MemberPasswordReminds'
CREATE TABLE [dbo].[MemberPasswordReminds] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [GUID] uniqueidentifier  NOT NULL,
    [IsActivated] bit  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL,
    [Member_ID] int  NOT NULL
);
GO

-- Creating table 'ContactRequests'
CREATE TABLE [dbo].[ContactRequests] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Mail] nvarchar(max)  NOT NULL,
    [Message] nvarchar(max)  NOT NULL,
    [IsDeleted] bit  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL,
    [Member_ID] int  NULL
);
GO

-- Creating table 'PostCategories'
CREATE TABLE [dbo].[PostCategories] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Post_ID] int  NOT NULL,
    [Category_ID] int  NOT NULL
);
GO

-- Creating table 'ContactResponses'
CREATE TABLE [dbo].[ContactResponses] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Message] nvarchar(max)  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [ModifiedDate] datetime  NOT NULL,
    [ContactRequest_ID] int  NOT NULL,
    [Member_ID] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Members'
ALTER TABLE [dbo].[Members]
ADD CONSTRAINT [PK_Members]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MemberRoles'
ALTER TABLE [dbo].[MemberRoles]
ADD CONSTRAINT [PK_MemberRoles]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MemberSettings'
ALTER TABLE [dbo].[MemberSettings]
ADD CONSTRAINT [PK_MemberSettings]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sections'
ALTER TABLE [dbo].[Sections]
ADD CONSTRAINT [PK_Sections]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Languages'
ALTER TABLE [dbo].[Languages]
ADD CONSTRAINT [PK_Languages]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [PK_Posts]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Comments'
ALTER TABLE [dbo].[Comments]
ADD CONSTRAINT [PK_Comments]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Pages'
ALTER TABLE [dbo].[Pages]
ADD CONSTRAINT [PK_Pages]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Tags'
ALTER TABLE [dbo].[Tags]
ADD CONSTRAINT [PK_Tags]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Categories'
ALTER TABLE [dbo].[Categories]
ADD CONSTRAINT [PK_Categories]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'PageTags'
ALTER TABLE [dbo].[PageTags]
ADD CONSTRAINT [PK_PageTags]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'PostTags'
ALTER TABLE [dbo].[PostTags]
ADD CONSTRAINT [PK_PostTags]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Sets'
ALTER TABLE [dbo].[Sets]
ADD CONSTRAINT [PK_Sets]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'LogRequests'
ALTER TABLE [dbo].[LogRequests]
ADD CONSTRAINT [PK_LogRequests]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'LogExceptions'
ALTER TABLE [dbo].[LogExceptions]
ADD CONSTRAINT [PK_LogExceptions]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID], [GUID] in table 'MemberPasswordReminds'
ALTER TABLE [dbo].[MemberPasswordReminds]
ADD CONSTRAINT [PK_MemberPasswordReminds]
    PRIMARY KEY CLUSTERED ([ID], [GUID] ASC);
GO

-- Creating primary key on [ID] in table 'ContactRequests'
ALTER TABLE [dbo].[ContactRequests]
ADD CONSTRAINT [PK_ContactRequests]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'PostCategories'
ALTER TABLE [dbo].[PostCategories]
ADD CONSTRAINT [PK_PostCategories]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'ContactResponses'
ALTER TABLE [dbo].[ContactResponses]
ADD CONSTRAINT [PK_ContactResponses]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Members_ID] in table 'MemberRoles'
ALTER TABLE [dbo].[MemberRoles]
ADD CONSTRAINT [FK_MemberRoleMember]
    FOREIGN KEY ([Members_ID])
    REFERENCES [dbo].[Members]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberRoleMember'
CREATE INDEX [IX_FK_MemberRoleMember]
ON [dbo].[MemberRoles]
    ([Members_ID]);
GO

-- Creating foreign key on [Role_ID] in table 'MemberRoles'
ALTER TABLE [dbo].[MemberRoles]
ADD CONSTRAINT [FK_RoleMemberRole]
    FOREIGN KEY ([Role_ID])
    REFERENCES [dbo].[Roles]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoleMemberRole'
CREATE INDEX [IX_FK_RoleMemberRole]
ON [dbo].[MemberRoles]
    ([Role_ID]);
GO

-- Creating foreign key on [MemberSettings_ID] in table 'Members'
ALTER TABLE [dbo].[Members]
ADD CONSTRAINT [FK_MemberMemberSettings]
    FOREIGN KEY ([MemberSettings_ID])
    REFERENCES [dbo].[MemberSettings]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberMemberSettings'
CREATE INDEX [IX_FK_MemberMemberSettings]
ON [dbo].[Members]
    ([MemberSettings_ID]);
GO

-- Creating foreign key on [Language_ID] in table 'Sections'
ALTER TABLE [dbo].[Sections]
ADD CONSTRAINT [FK_LanguageSection]
    FOREIGN KEY ([Language_ID])
    REFERENCES [dbo].[Languages]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LanguageSection'
CREATE INDEX [IX_FK_LanguageSection]
ON [dbo].[Sections]
    ([Language_ID]);
GO

-- Creating foreign key on [Section_ID] in table 'Pages'
ALTER TABLE [dbo].[Pages]
ADD CONSTRAINT [FK_SectionPage]
    FOREIGN KEY ([Section_ID])
    REFERENCES [dbo].[Sections]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SectionPage'
CREATE INDEX [IX_FK_SectionPage]
ON [dbo].[Pages]
    ([Section_ID]);
GO

-- Creating foreign key on [Section_ID] in table 'Categories'
ALTER TABLE [dbo].[Categories]
ADD CONSTRAINT [FK_SectionCategory]
    FOREIGN KEY ([Section_ID])
    REFERENCES [dbo].[Sections]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SectionCategory'
CREATE INDEX [IX_FK_SectionCategory]
ON [dbo].[Categories]
    ([Section_ID]);
GO

-- Creating foreign key on [Post_ID] in table 'Comments'
ALTER TABLE [dbo].[Comments]
ADD CONSTRAINT [FK_PostComment]
    FOREIGN KEY ([Post_ID])
    REFERENCES [dbo].[Posts]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostComment'
CREATE INDEX [IX_FK_PostComment]
ON [dbo].[Comments]
    ([Post_ID]);
GO

-- Creating foreign key on [Page_ID] in table 'Comments'
ALTER TABLE [dbo].[Comments]
ADD CONSTRAINT [FK_PageComment]
    FOREIGN KEY ([Page_ID])
    REFERENCES [dbo].[Pages]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PageComment'
CREATE INDEX [IX_FK_PageComment]
ON [dbo].[Comments]
    ([Page_ID]);
GO

-- Creating foreign key on [Member_ID] in table 'Pages'
ALTER TABLE [dbo].[Pages]
ADD CONSTRAINT [FK_MemberPage]
    FOREIGN KEY ([Member_ID])
    REFERENCES [dbo].[Members]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberPage'
CREATE INDEX [IX_FK_MemberPage]
ON [dbo].[Pages]
    ([Member_ID]);
GO

-- Creating foreign key on [Member_ID] in table 'Comments'
ALTER TABLE [dbo].[Comments]
ADD CONSTRAINT [FK_MemberComment]
    FOREIGN KEY ([Member_ID])
    REFERENCES [dbo].[Members]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberComment'
CREATE INDEX [IX_FK_MemberComment]
ON [dbo].[Comments]
    ([Member_ID]);
GO

-- Creating foreign key on [Member_ID] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [FK_MemberPost]
    FOREIGN KEY ([Member_ID])
    REFERENCES [dbo].[Members]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberPost'
CREATE INDEX [IX_FK_MemberPost]
ON [dbo].[Posts]
    ([Member_ID]);
GO

-- Creating foreign key on [Page_ID] in table 'PageTags'
ALTER TABLE [dbo].[PageTags]
ADD CONSTRAINT [FK_PagePageTags]
    FOREIGN KEY ([Page_ID])
    REFERENCES [dbo].[Pages]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PagePageTags'
CREATE INDEX [IX_FK_PagePageTags]
ON [dbo].[PageTags]
    ([Page_ID]);
GO

-- Creating foreign key on [Tag_ID] in table 'PageTags'
ALTER TABLE [dbo].[PageTags]
ADD CONSTRAINT [FK_PageTagsTag]
    FOREIGN KEY ([Tag_ID])
    REFERENCES [dbo].[Tags]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PageTagsTag'
CREATE INDEX [IX_FK_PageTagsTag]
ON [dbo].[PageTags]
    ([Tag_ID]);
GO

-- Creating foreign key on [Post_ID] in table 'PostTags'
ALTER TABLE [dbo].[PostTags]
ADD CONSTRAINT [FK_PostPostTags]
    FOREIGN KEY ([Post_ID])
    REFERENCES [dbo].[Posts]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostPostTags'
CREATE INDEX [IX_FK_PostPostTags]
ON [dbo].[PostTags]
    ([Post_ID]);
GO

-- Creating foreign key on [Tag_ID] in table 'PostTags'
ALTER TABLE [dbo].[PostTags]
ADD CONSTRAINT [FK_TagPostTags]
    FOREIGN KEY ([Tag_ID])
    REFERENCES [dbo].[Tags]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TagPostTags'
CREATE INDEX [IX_FK_TagPostTags]
ON [dbo].[PostTags]
    ([Tag_ID]);
GO

-- Creating foreign key on [Set_ID] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [FK_PostSet]
    FOREIGN KEY ([Set_ID])
    REFERENCES [dbo].[Sets]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostSet'
CREATE INDEX [IX_FK_PostSet]
ON [dbo].[Posts]
    ([Set_ID]);
GO

-- Creating foreign key on [Language_ID] in table 'Tags'
ALTER TABLE [dbo].[Tags]
ADD CONSTRAINT [FK_LanguageTag]
    FOREIGN KEY ([Language_ID])
    REFERENCES [dbo].[Languages]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LanguageTag'
CREATE INDEX [IX_FK_LanguageTag]
ON [dbo].[Tags]
    ([Language_ID]);
GO

-- Creating foreign key on [Member_ID] in table 'MemberPasswordReminds'
ALTER TABLE [dbo].[MemberPasswordReminds]
ADD CONSTRAINT [FK_MemberMemberPasswordRemind]
    FOREIGN KEY ([Member_ID])
    REFERENCES [dbo].[Members]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberMemberPasswordRemind'
CREATE INDEX [IX_FK_MemberMemberPasswordRemind]
ON [dbo].[MemberPasswordReminds]
    ([Member_ID]);
GO

-- Creating foreign key on [Member_ID] in table 'ContactRequests'
ALTER TABLE [dbo].[ContactRequests]
ADD CONSTRAINT [FK_ContactRequestMember]
    FOREIGN KEY ([Member_ID])
    REFERENCES [dbo].[Members]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContactRequestMember'
CREATE INDEX [IX_FK_ContactRequestMember]
ON [dbo].[ContactRequests]
    ([Member_ID]);
GO

-- Creating foreign key on [Post_ID] in table 'PostCategories'
ALTER TABLE [dbo].[PostCategories]
ADD CONSTRAINT [FK_PostPostCategory]
    FOREIGN KEY ([Post_ID])
    REFERENCES [dbo].[Posts]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostPostCategory'
CREATE INDEX [IX_FK_PostPostCategory]
ON [dbo].[PostCategories]
    ([Post_ID]);
GO

-- Creating foreign key on [Category_ID] in table 'PostCategories'
ALTER TABLE [dbo].[PostCategories]
ADD CONSTRAINT [FK_CategoryPostCategory]
    FOREIGN KEY ([Category_ID])
    REFERENCES [dbo].[Categories]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryPostCategory'
CREATE INDEX [IX_FK_CategoryPostCategory]
ON [dbo].[PostCategories]
    ([Category_ID]);
GO

-- Creating foreign key on [ContactRequest_ID] in table 'ContactResponses'
ALTER TABLE [dbo].[ContactResponses]
ADD CONSTRAINT [FK_ContactRequestContactResponse]
    FOREIGN KEY ([ContactRequest_ID])
    REFERENCES [dbo].[ContactRequests]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContactRequestContactResponse'
CREATE INDEX [IX_FK_ContactRequestContactResponse]
ON [dbo].[ContactResponses]
    ([ContactRequest_ID]);
GO

-- Creating foreign key on [Member_ID] in table 'ContactResponses'
ALTER TABLE [dbo].[ContactResponses]
ADD CONSTRAINT [FK_MemberContactResponse]
    FOREIGN KEY ([Member_ID])
    REFERENCES [dbo].[Members]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberContactResponse'
CREATE INDEX [IX_FK_MemberContactResponse]
ON [dbo].[ContactResponses]
    ([Member_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------